import axios from 'axios';
import type { RouteRecordNormalized } from 'vue-router';
import { UserState } from '@/store/modules/user/types';
import { MarssLoginModel, MarssLoginRes } from '@/types/auth';
import { getToken } from '@/utils/auth';

// 用户登录，返回的是解包后的 data
export function login(loginData: MarssLoginModel) {
  return axios.post<MarssLoginRes>('/api/auth/login', loginData);
}

export function logout() {
  // 获取 Access Token
  const token = getToken();
  // 发送POST请求
  return axios.post('/api/auth/logout', null, {
    headers: {
      Authorization: `Bearer ${token}`,
    },
  });
}

export function getUserInfo() {
  return axios.post<UserState>('/api/user/info');
}

export function getMenuList() {
  return axios.post<RouteRecordNormalized[]>('/api/user/menu');
}
